/*
 * @Description: 
 * @Author: rendc
 * @Date: 2025-10-24 09:07:18
 * @LastEditors: rendc
 * @LastEditTime: 2025-10-24 11:46:49
 */
console.log("array");
var arr = [1, 3, 4, 12, 22, 34, 56, 2, 7, 5, 6, 9];
console.log('🤡 CC - 原始 - arr:', arr);
// arr.sort(); // 会改变原始值
// console.log('🤡 CC - 默认排序 - arr:', arr);

// 按照数字大小排序
arr.sort(
  function (a, b) {
    return 0; // 不排序
    // return 1; // 不排序
    // return -1; // 倒序输出 相当于 reverse()
    // return a - b; // 升序
    // return b - a; // 降序
    // 无返回值 不排序
  }
);
// 会改变原始值
console.log('🤡 CC - 数字排序 - arr:', arr);


var arr1 = [1, 2, 3];
var arr2 = [4, 5];
var arr3 = [6, 7];
var arrAll = arr1.concat(arr2, arr3, [8, 9], "hello");
console.log('🤡 CC - arr1:', arr1); // [1,2,3]
console.log('🤡 CC - arrAll:', arrAll);// [1,2,3,4,...,7,"hello"]

console.log('🤡 CC - arr1:', arr1);//[1,2,3]
var result = arr1.slice(0, 2);
console.log('🤡 CC - arr1:', arr1);// [1,2,3]
console.log('🤡 CC - result:', result); // [1,2]

// 获取所有元素
console.log('🤡 CC - arr1:', arr1);//[1,2,3]
var result = arr1.slice(0, arr1.length);
console.log('🤡 CC - arr1:', arr1);// [1,2,3]
console.log('🤡 CC - result:', result); // [1,2,3]

// 获取所有元素
console.log('🤡 CC - arr1:', arr1);//[1,2,3]
var result = arr1.slice(0);
console.log('🤡 CC - arr1:', arr1);// [1,2,3]
console.log('🤡 CC - result:', result); // [1,2,3]


console.log('🤡 CC - arr1:', arr1);//[1,2,3]
var result = arr1.slice(0, 0);
console.log('🤡 CC - arr1:', arr1);// [1,2,3]
console.log('🤡 CC - result0:', result); // []


console.log('🤡 CC - arr1:', arr1);//[1,2,3]
var result = arr1.slice(0, -1);
console.log('🤡 CC - arr1:', arr1);// [1,2,3]
console.log('🤡 CC - result-1:', result); // []
// end -1 表示最后一个元素(0,2)

// var str = "hello";
// var result = Array.from(arr);
// console.log('🤡 CC - result:', result);
var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', 'l', 'o'];
console.log('🤡 CC - arr:', arr);
var result = arr.slice(0, 2);
console.log('🤡 CC - result:', result); //['h', 'e']
var result = arr.slice(0, -1);
// var result = arr.slice(0, 4);
console.log('🤡 CC - result:', result); //['h', 'e', 'l', 'l',]
var result = arr.slice(0, -6);
// var result = arr.slice(0, );
console.log('🤡 CC - result:', result); //[]
var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', 'l', 'o'];
var result = arr.slice();
// var result = arr.slice(0, );
console.log('🤡 CC - arr-1:', arr);
arr[1] = "ooooo";
console.log('🤡 CC - arr-1:', arr);
console.log('🤡 CC - result-1:', result); //[]

var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', 'l', 'o'];
var result = arr.slice(1, 2);
// console.log('🤡 CC - arr-1:', arr);
console.log('🤡 CC - result-1:', result); //['e']

var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', '1', 'o'];
var result = arr.slice(-2, -1);
console.log('🤡 CC - result-1:', result); //[]

var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', '1', 'o'];
var result = arr.slice(-2);
console.log('🤡 CC - result-1:', result); //[]


var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', '1', 'o'];
var result = arr.splice(2, 3, "w");
console.log('🤡 CC - arr:', arr);// [h e w]

var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', '1', 'o'];
var result = arr.splice(1, 0, "w", 'y');
console.log('🤡 CC - arr:', arr);// []

var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', '1', 'o'];
var result = arr.splice(2, 1, '0', '2');
console.log('🤡 CC - arr:', arr);
// ['h', 'e', '0', '2', '1', 'o']


var arr = [0, 1, 2, 3, 4];
var result = arr.splice(2, 2, 0, 1, 2, 2);
console.log('🤡 CC - arr:', arr);
console.log('🤡 CC - result:', result);
[0, 1, 0, 1, 2, 2, 4]

var arr = ['h', 'e', 'l', 'e', 'o'];
var result = arr.indexOf('e', 4);
//  index 1
//  index 2 
//  index 4
console.log('🤡 CC - arr:', arr);
console.log('🤡 CC - result:', result);

var arr = ['0', '1', '2', '3', '4'];
var arr = ['h', 'e', 'l', 'e', 'o'];
var result = arr.lastIndexOf('e', 3);
// console.log('🤡 CC - arr:', arr);
console.log('🤡 CC - result:', result);

var arr = [0, 1, 2, 3, 4, 5];
console.log('🤡 CC - arr:', arr);
// var arr = [];
var result = arr.every(
  // 检测arr中的number是否都小于5
  function (number) {
    return (number * 2) > 5;
  }
);
console.log('🤡 CC - arr:', arr);
console.log('🤡 CC - result:', result);


var arr = [0, 1, 2, 3, 4, 5];
console.log('🤡 CC - some - arr:', arr);
var arr = [];
var result = arr.some(
  // 检测arr中的number有没有满足条件的
  function (number) {
    return (number * 2) > 5;
  }
);
console.log('🤡 CC - some - arr:', arr);
console.log('🤡 CC - some - result:', result);

var arr = [0, 1, 2, 3, 4, 5];
console.log('🤡 CC - filter - arr:', arr);
var arr = [];
var result = arr.filter(
  // 检测arr中的哪些元素是满足条件的
  function (number) {
    return number * 2 > 30;
  }
);
console.log('🤡 CC - filter - arr:', arr);
console.log('🤡 CC - filter - result:', result);

var arr = [0, 1, 2, 3, 4, 5];
console.log('🤡 CC - map - arr:', arr);
// var arr = [];
var result = arr.map(
  // 检测arr中的哪些元素是满足条件的
  function (number) {
    return number * 2 > 3;
  }
);
console.log('🤡 CC - map - arr:', arr);
console.log('🤡 CC - map - result:', result);

// var arr = [0, 1, 2, 3, 4, 5];
var arr = ['h', 'e', 'l', 'e', 'o'];

console.log('🤡 CC - forEach - arr:', arr);
// var arr = [];
arr.forEach(
  // 检测arr中的哪些元素是满足条件的
  function (number, index) {
    console.log('🤡 CC :', index + "-" + number);
    // console.log('🤡 CC - number, index:', number, index);
    // return number * 2 > 3;
  }
);
console.log('🤡 CC - forEach - arr:', arr);